package com.ygxsk.carhome.ui;

import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.afollestad.materialdialogs.MaterialDialog;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.blankj.utilcode.util.Utils;
import com.gyf.immersionbar.ImmersionBar;
import com.gyf.immersionbar.components.SimpleImmersionFragment;
import com.kongzue.dialogx.dialogs.PopTip;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.tencent.mmkv.MMKV;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.alertview.AlertView;
import com.ygxsk.carhome.alertview.OnItemClickListener;
import com.ygxsk.carhome.constant.ConstantApi;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.listener.DoSomeThingListener;
import com.ygxsk.carhome.listener.DoubleClickListener;
import com.ygxsk.carhome.response.EvaluateWadeDataInfo;
import com.ygxsk.carhome.retrofit.AddLogUpLoadInfo;
import com.ygxsk.carhome.retrofit.ApiException;
import com.ygxsk.carhome.retrofit.ApiRequestSubListener;
import com.ygxsk.carhome.retrofit.ApiService;
import com.ygxsk.carhome.retrofit.ErrorConsumer;
import com.ygxsk.carhome.retrofit.NetworkManager;
import com.ygxsk.carhome.retrofit.ResponseTransformer;
import com.ygxsk.carhome.sys.Session;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.StringCodeUtils;
import com.ygxsk.carhome.utils.ViewUitls;
import com.ygxsk.integrated.retrofit.Parameterkey;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import rxdogtag2.RxDogTag;
import rxdogtag2.autodispose2.AutoDisposeConfigurer;

/**
 * 可以使用沉浸式的Fragment基类
 *
 * @author geyifeng
 * @date 2017/4/7
 */
@SuppressWarnings("deprecation")
public abstract class BaseImmersionFragment extends SimpleImmersionFragment implements OnRequestListenFragment {

    //protected String mTag = this.getClass().getSimpleName();
    private Unbinder unbinder;
    protected Activity mActivityInstance;
    //可以去掉this引用
    protected BaseImmersionFragment mFragmentInstance;
    protected View mRootView;
//    protected Toolbar toolbar;

    protected FrameLayout loading;
    protected TextView no_data_one;

    private RelativeLayout layoutNoData;
    private RelativeLayout layoutNullData;
    private ImageView imageViewErrorNull;
    private TextView textViewErrorNull;

    protected Session mSession;

    //在fragment之中添加的适配器集合
    protected CompositeDisposable mCompositeDisposable = new CompositeDisposable();

    //页面通用的弹窗
    protected AlertView mAlertView;
    //页面通用的提交弹窗
    protected MaterialDialog materialDialog;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);

        mFragmentInstance = this;
        mActivityInstance = (Activity) context;

        LogUtils.d(ConstantSign.LOGCAT_NOMAL + mFragmentInstance.getClass().getSimpleName() + "--onAttach--onAttach--onAttach");

        //在生命周期的早期植入，
        RxDogTag.builder()
                .configureWith(AutoDisposeConfigurer::configure)
                .install();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mSession = Session.get(this.getActivity());

        initDataBeforeView(savedInstanceState);

    }

    @Override
    public void onResume() {
        super.onResume();

        // TODO: 2023-04-11 要不要在这里  做session的再取出值内容
        //LogUtils.d(ConstantSign.LOGCAT_NOMAL + "BaseImmersionFragment.this-----onResume--->" + BaseImmersionFragment.this);

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "BaseImmersionFragment.this-----onCreateView--->" + BaseImmersionFragment.this.getClass().getSimpleName());

        if (mRootView == null) {

            mRootView = inflater.inflate(getLayoutId(), container, false);

            initLoading(mRootView);

        } else {
            ViewGroup viewGroup = (ViewGroup) mRootView.getParent();
            if (viewGroup != null) {
                viewGroup.removeView(mRootView);
            }
        }

        return mRootView;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

//        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "BaseImmersionFragment.this-----onViewCreated--->" + BaseImmersionFragment.this);
        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "BaseImmersionFragment.this-----onViewCreated--->" + BaseImmersionFragment.this.getClass().getSimpleName());

        unbinder = ButterKnife.bind(this, view);

//        statusBarView = view.findViewById(R.id.status_bar_view);

        //这个好像是通用的，单个页面有个单个通用的；2023-7-5 17:34:13 暂时隐藏掉；
//        toolbar = view.findViewById(R.id.toolbar);

        fitsLayoutOverlap();

        initView();

        initData();

        setListener();

    }

    protected void sendMsg(Handler mBaseHandler, int what, Object obj) {
        Message msg = mBaseHandler.obtainMessage(what);
        msg.obj = obj;
        mBaseHandler.sendMessage(msg);
    }

    //    protected View statusBarView;
    protected abstract void gainDatas();

    /**
     * 做非200的界面处理的
     */
    public void methodNotSuccessData(int what_method, String serverCode, String serverMessage) {

        // TODO: 2023-04-26 08:07 如果是30003的报错，一律将 serverMessage 做一个转换； 换成数据响应异常：
//        if (TextUtils.equals(serverCode, ConstantSign.REQUEST_30003)){
//            serverMessage = ConstantSign.REQUEST_30003;
//        }

    }

    protected void initLoading(View _view) {

        if (_view != null) {

            loading = (FrameLayout) _view.findViewById(R.id.loadingfragmentall);

            if (loading != null) {

                //只有当网络不给力的时候这个屏幕是可以点击的
                if (NetworkUtils.isConnected()) {//网络可用 这个布局是不可点击的

                    loading.setFocusable(false);
                    loading.setPressed(false);

                    loading.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // Consume click
                        }
                    });

                } else {//网络不可用 那么 这个就是重试

                    loading.setFocusable(true);
                    loading.setPressed(true);//网络未连接具备点击事件。

                    loading.setOnClickListener(new NodataClicker());//界面上刷新重试

                    // : 2023-04-21 09:01 如果消除点击刷新就可以屏蔽掉该页面
//                    loading.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            // Consume click
//                        }
//                    });

                }

                layoutNoData = ViewUitls.getLayoutNoData(loading);
                no_data_one = ViewUitls.getNo_data_one(loading);

                //废弃但不能删除
                //buttonTryAgain = ViewUitls.getButtonTryAgain(loading);
                //buttonTryAgain.setOnClickListener(new NodataClicker());

                //================================================================
                layoutNullData = ViewUitls.getLayoutNullData(loading);
                imageViewErrorNull = ViewUitls.getImageViewErrorNull(loading);
                textViewErrorNull = ViewUitls.getTextViewErrorNull(loading);

                //再次做数据隐藏
                if (loading.getVisibility() == View.VISIBLE) {
                    loading.setVisibility(View.GONE);
                }
            }

        } else {
//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "initLoading--initLoading--initLoading  是空");
        }
    }

    public class NodataClicker implements View.OnClickListener {

        private AlertView alertViewNet;

        @Override
        public void onClick(View v) {

            if (!DoubleClickListener.isFastDoubleClick()) {

                if (NetworkUtils.isConnected()) {

                    onClickNodata(v);

                } else {

                    CommUtils.checkDialog(alertViewNet);

                    //打开网络设置
                    alertViewNet = new AlertView(ConstantSign.ALERT_TITLE, //
                            ConstantSign.NET_WORKSETTING, //
                            getString(R.string.alert_cancel), //
                            new String[]{getString(R.string.alert_open)}, //
                            null, //
                            BaseImmersionFragment.this.getActivity(),//
                            AlertView.Style.Alert, //
                            new OnItemClickListener() {//
                                @Override
                                public void onItemClick(Object o, int position) {//
                                    if (position != AlertView.CANCELPOSITION) {
                                        NetworkUtils.openWirelessSettings();//
                                    }
                                }//
                            });

                    alertViewNet.setCancelable(true)//
                            .show();//
                }
            }

        }

    }

    public void loadingGone() {

        if (loading != null) {

            ViewUitls.LoadingGone(loading);

            if (layoutNoData != null) {
                if (layoutNoData.getVisibility() == View.VISIBLE) {
                    layoutNoData.setVisibility(View.GONE);
                }
            }

            if (layoutNullData != null) {
                if (layoutNullData.getVisibility() == View.VISIBLE) {
                    layoutNullData.setVisibility(View.GONE);
                }
            }

        }

    }


    public void fillNullDataView(String message, int imageResourecesId) {

        if (loading != null) {

            //LogUtils.d("itchen---fillNullDataView--->loading 不是null");

            ViewUitls.LoadingVisible(loading);

            if (layoutNoData != null) {
                if (layoutNoData.getVisibility() == View.VISIBLE) {
                    layoutNoData.setVisibility(View.GONE);
                }
            }

            if (layoutNullData != null) {
                if (layoutNullData.getVisibility() == View.GONE) {
                    layoutNullData.setVisibility(View.VISIBLE);
                }
            }

            if (textViewErrorNull != null) {
                textViewErrorNull.setText(message);
            }

            if (imageViewErrorNull != null) {

                //2018年02月06日封装为动态填充空界面图片。
                imageViewErrorNull.setImageDrawable(ContextCompat.getDrawable(Utils.getApp(), imageResourecesId));

            }

        } else {
//            LogUtils.d("itchen---fillNullDataView--->loading 是 null");
        }

    }

    public void netWorkError() {

        if (isAdded()) {

            if (loading != null) {

                ViewUitls.LoadingVisible(loading);
                //=============================================================
                if (layoutNoData != null) {
                    if (layoutNoData.getVisibility() == View.GONE) {
                        layoutNoData.setVisibility(View.VISIBLE);
                    }
                }
                //=============================================================
                if (layoutNullData != null) {
                    if (layoutNullData.getVisibility() == View.VISIBLE) {
                        layoutNullData.setVisibility(View.GONE);
                    }
                }
                //=============================================================
            }

        }

    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        if (unbinder != null) {
            unbinder.unbind();
        }

        CommUtils.checkMaterialDialog(materialDialog);

        if (mCompositeDisposable != null) {
            //释放句柄
            mCompositeDisposable.clear();
        }
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        //旋转屏幕为什么要重新设置布局与状态栏重叠呢？因为旋转屏幕有可能使状态栏高度不一样，如果你是使用的静态方法修复的，所以要重新调用修复
        fitsLayoutOverlap();
    }

    protected void initDataBeforeView(Bundle savedInstanceState) {

    }

    /**
     * Gets layout id.
     *
     * @return the layout id
     */
    protected abstract int getLayoutId();


    @Override
    public void initImmersionBar() {
        ImmersionBar.with(this)//
                //.statusBarColor(R.color.colorPrimary)//
                .keyboardEnable(false)//
                .init();//
    }

    /**
     * 初始化数据
     */
    protected void initData() {

        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "--initData--initData--initData--initData--initData--initData");

        //这里会导致 直接获取了两次gaindatas
        //gainDatas();

        if (!NetworkUtils.isConnected()) {
            netWorkError();
        }

    }

    /**
     * view与数据绑定
     */
    protected void initView() {

//        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "走到父类的--initView--initView--initView---initView--initView--initView");

    }

    /**
     * 设置监听
     */
    protected void setListener() {

    }

    private void fitsLayoutOverlap() {

//        ImmersionBar.setTitleBar(this, toolbar);

    }


    /**
     * 智能的分页内容
     *
     * @param _totalCounts
     * @param _smartRefreshLayout
     */
    public int setSmartPaging(int _totalCounts, SmartRefreshLayout _smartRefreshLayout) {

        int currentTotalPageNumberCount = 1;

        //总共有几个页面
        if (_totalCounts < Parameterkey.pageSize_default) {//数据总值内容是1，说明不够10条或者刚好10条数据，只有1页。刚好10条是1；

            currentTotalPageNumberCount = Parameterkey.totalPageNumberCount_onePage;
            _smartRefreshLayout.finishLoadMoreWithNoMoreData();

            //pageNum_upLoad = Parameterkey.pageNum_default_first;//1

            //LogUtils.d(ConstantSign.LOGCAT_NOMAL + "总数量 小于10-总共有1页数据");

            return currentTotalPageNumberCount;

        } else if (_totalCounts == Parameterkey.pageSize_default) {

            currentTotalPageNumberCount = Parameterkey.totalPageNumberCount_onePage;
            _smartRefreshLayout.finishLoadMoreWithNoMoreData();

            //pageNum_upLoad = Parameterkey.pageNum_default_first;//1

//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "总数量 等于10-总共有1页数据");

            return currentTotalPageNumberCount;

        } else if (_totalCounts > Parameterkey.pageSize_default) {//多于10

            currentTotalPageNumberCount = _totalCounts / Parameterkey.pageSize_default + Parameterkey.increment_unit;//(11/10=1)
            _smartRefreshLayout.setEnableLoadMore(true);

//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "总量是=>" + _totalCounts + "条--总共有->" + currentTotalPageNumberCount + "个页面");

            //pageNum_upLoad = totalCounts / pageSize_upLoad + 1;

            return currentTotalPageNumberCount;

        }

        return currentTotalPageNumberCount;

    }

    /**
     * 展开没有更多数据
     */
    public void setFinishLoadMoreWithNoMoreData(SmartRefreshLayout smartRefreshLayout, boolean isEnable) {
        //这里不让上拉了
        if (smartRefreshLayout != null) {
            smartRefreshLayout.setEnableFooterFollowWhenNoMoreData(true);
            smartRefreshLayout.finishLoadMoreWithNoMoreData();
        }
    }

    /**
     * 关闭上拉加载更多效果
     */
    public void setEnableLoadmore(SmartRefreshLayout smartRefreshLayout, boolean isEnable) {
        //这里不让上拉了
        if (smartRefreshLayout != null) {
            smartRefreshLayout.setEnableLoadMore(isEnable);
        }
    }

    //直接拨打电话的能力
    protected void clickButton_toCallPhone(Activity _activity, String mPhoneNumber, String _buinessType) {

        if (!TextUtils.isEmpty(mPhoneNumber)) {

            CommUtils.checkDialog(mAlertView);

            //二次确认弹窗提示
            mAlertView = new AlertView(ConstantSign.ALERTVIEW_TITLE_FOR_PHONE,//
                    StringCodeUtils.mobileEncrypt(mPhoneNumber), //mPhoneNumber 2023年9月22日11:19:40 需求手机号脱敏
                    ConstantSign.ALERTVIEW_LEFT_CANCEL,//
                    new String[]{ConstantSign.ALERTVIEW_RIGHT_COPY_INFORMATION}, //
                    null, //
                    _activity, //
                    AlertView.Style.Alert,//
                    new com.ygxsk.carhome.alertview.OnItemClickListener() {
                        @Override
                        public void onItemClick(Object o, int position) {

                            if (position != AlertView.CANCELPOSITION) {

                                if (!TextUtils.isEmpty(mPhoneNumber)) {
                                    _activity.startActivity(CommUtils.callThePhoneNumAction_dial(mPhoneNumber));

                                    callPhone_upLoad_intent(mPhoneNumber, _buinessType);

                                } else {
                                    ToastUtils.showShort(R.string.hasfailgetphonenumber);
                                }

                            }
                        }
                    }
            );

            mAlertView.setCancelable(true).show();

        } else {

            String phoneInfo = getString(R.string.hasfailgetphonenumber);
            PopTip.show(phoneInfo).iconWarning();

        }

    }

    /*
     * @Author:itchenqi175@163.com
     * @Time:2023-08-08  16:18
     * @Description:界面之中涉及一些提交成功的封装
     */
    protected void methodSubmitSuccess(Activity _activity, DoSomeThingListener _doSomeThingListener) {

        CommUtils.checkDialog(mAlertView);
        mAlertView = new AlertView(StringUtils.getString(R.string.clearaddorsubmitsuretitletips), //
                getString(R.string.add_submit_success), //
                null, //
                null, //
                null, //
                _activity, //
                AlertView.Style.Alert, //
                null);
        mAlertView.setCancelable(true).show();//

        mCompositeDisposable.add(Observable.timer(ConstantApi.ALERTVIEW_TIME_DELAY, TimeUnit.MILLISECONDS)
                .subscribeOn(AndroidSchedulers.mainThread())//
                .observeOn(AndroidSchedulers.mainThread())//
//                                .compose(BaseImmersionFragment.this.)
                //.compose(BaseImmersionFragment.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {

                        if (mAlertView != null) {
                            if (mAlertView.isShowing()) {
                                mAlertView.dismiss();
                                mAlertView = null;
                            }
                        }

                        if (_doSomeThingListener != null) {
                            _doSomeThingListener.doSomeThing();
                        }

                    }
                }));

    }

    /*
     * @Author:itchenqi175@163.com
     * @Time:2023-08-08  16:18
     * @Description:界面之中涉及一些提交成功的封装,设置一个提交之后两秒的延迟提示
     */
    protected void methodSubmitSuccessTwoSecond(Activity _activity, DoSomeThingListener _doSomeThingListener) {

        CommUtils.checkDialog(mAlertView);
        mAlertView = new AlertView(StringUtils.getString(R.string.clearaddorsubmitsuretitletips), //
                getString(R.string.add_submit_success), //
                null, //
                null, //
                null, //
                _activity, //
                AlertView.Style.Alert, //
                null);
        mAlertView.setCancelable(true).show();//

        mCompositeDisposable.add(Observable.timer(ConstantApi.UPDATE_GETAPP_PRIVACYAGREEMENT_DIALOG, TimeUnit.MILLISECONDS)
                .subscribeOn(AndroidSchedulers.mainThread())//
                .observeOn(AndroidSchedulers.mainThread())//
                //.compose(BaseImmersionFragment.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {

                        if (mAlertView != null) {
                            if (mAlertView.isShowing()) {
                                mAlertView.dismiss();
                                mAlertView = null;
                            }
                        }

                        if (_doSomeThingListener != null) {
                            _doSomeThingListener.doSomeThing();
                        }

                    }
                }));

    }

    // TODO: 2023-09-05 11:28  上传用户拨打电话的意图

    //上传用户拨打电话的意图
    private void callPhone_upLoad_intent(String _phone, String _businessType_click_model) {

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());
        map.put(Parameterkey.communityId, mSession.getCommunityId());
        map.put(Parameterkey.phone, _phone);

        //------------------------------------------------------------------------------------------------------------------
        ArrayList<EvaluateWadeDataInfo> typeValueList = null;
//        String _businessType = "";
        String jsonString = MMKV.defaultMMKV().decodeString(ConstantSign.P_MMKV_CALL_PHONE);
        if (!TextUtils.isEmpty(jsonString)) {
            typeValueList = (ArrayList<EvaluateWadeDataInfo>) JSON.parseArray(jsonString, EvaluateWadeDataInfo.class);
//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + "typeValueList-->" + typeValueList);
        }

        if (typeValueList != null && !typeValueList.isEmpty()) {

            Iterator<EvaluateWadeDataInfo> iterator = typeValueList.iterator();
            if (iterator != null) {
                while (iterator.hasNext()) {
                    EvaluateWadeDataInfo item = iterator.next();
                    if (item != null) {
                        if (TextUtils.equals(_businessType_click_model, item.getCode())) {//判断条件
                            //执行 取出 value 上传，code仅仅是用来做判断
                            map.put(Parameterkey.businessType, item.getValue());

                            break;
                        }
                    }
                }
            }

        }
        //------------------------------------------------------------------------------------------------------------------

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_ADDCALLHISTORY_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.addCallHistory_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(false);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .addCallHistory(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
//                .getListByType(Parameterkey.out_door_type)
                //.compose(ErrorActivity.this.bindUntilEvent(ActivityEvent.DESTROY))
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<String>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);
                    }
                })).subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String archiveTypes) throws Throwable {

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {

                    }
                });

    }

    //创建弹窗的类型，是加载数据或者是提交中
    protected void method_create_materialDialog(String _tipsToast) {
        CommUtils.checkMaterialDialog(materialDialog);
        //materialDialog = CommUtils.createMaterialDialog(mActivityInstance, ConstantSign.TIPS_LOADING);
        materialDialog = CommUtils.createMaterialDialog(mActivityInstance, _tipsToast);
    }

    protected void methodSingleSubmitSuccessCustomTitle(Activity _activity, String tileTips, DoSomeThingListener _doSomeThingListener) {

        CommUtils.checkDialog(mAlertView);

        mAlertView = new AlertView(StringUtils.getString(R.string.clearaddorsubmitsuretitletips), //
                tileTips, //
                null, //
                null, //
                null, //
                _activity, //
                AlertView.Style.Alert, //
                null);
        mAlertView.setCancelable(true).show();//

        mCompositeDisposable.add(Observable.timer(ConstantApi.ALERTVIEW_TIME_DELAY, TimeUnit.MILLISECONDS)
                .subscribeOn(AndroidSchedulers.mainThread())//
                .observeOn(AndroidSchedulers.mainThread())//
//                .compose(BaseImmersionFragment.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {

                        if (mAlertView != null) {
                            if (mAlertView.isShowing()) {
                                mAlertView.dismiss();
                                mAlertView = null;
                            }
                        }

                        if (_doSomeThingListener != null) {
                            _doSomeThingListener.doSomeThing();
                        }

                    }
                }));

    }

//    /**
//     * 报错提示封装
//     *
//     * @param apiException
//     */
//    private void function_apiException(ApiException apiException) {
//
//        if (apiException != null) {
//            if (!TextUtils.isEmpty(apiException.getDisplayMessage())) {
//                ToastUtils.showShort(apiException.getDisplayMessage());
//            }
//        }
//
//    }

    /**
     * 报错提示封装
     *
     * @param apiException
     */
    public void function_apiException(ApiException apiException) {

        if (apiException != null) {
            if (!TextUtils.isEmpty(apiException.getDisplayMessage())) {
                ToastUtils.showShort(apiException.getDisplayMessage());
            }
        }

    }

    //无数据的提示，要不要特殊提示的
    public void function_response_20002(String _serverCode, String _serverMessage, AddLogUpLoadInfo _addLogUpLoadInfo, boolean isShowToastOrNot) {

        String resultMessage = "";

        if (!TextUtils.isEmpty(_serverMessage)) {
            resultMessage = _serverMessage;
        } else {
            resultMessage = getResources().getString(R.string.action_abnormal_toast);
        }

        if (TextUtils.equals(_serverCode, ConstantSign.RESPONSE_20002)) {

            //{"data":"","message":"无数据","code":"20002"}
            //无数据这个就不提示了，因为筛选条件很多，一会一提示 不友好；
            if (_addLogUpLoadInfo.isAlertToUser()) {

                CommUtils.checkDialog(mAlertView);
                mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, resultMessage, true);
                mAlertView.show();

            } else {

                if (isShowToastOrNot) {
                    //如果让展示20002的空数据{"data":"","message":"无数据","code":"20002"}，那么就展示，主页列表一半不提示，显得多余
                    ToastUtils.showShort(resultMessage);
                }

//                if (!TextUtils.isEmpty(resultMessage)) {
//                    ToastUtils.showShort(resultMessage);
//                } else {
//                    ToastUtils.showShort(resultMessage);
//                }

            }

        } else if (_addLogUpLoadInfo.isAlertToUser()) {

            //用于优惠券发放 和优惠礼包的发放
            //{"data":"","message":"无可用优惠券！","code":"20902"}
            CommUtils.checkDialog(mAlertView);
            mAlertView = CommUtils.method_showAlertViewSingleSlowly(mActivityInstance, ConstantSign.ALERT_TITLE, resultMessage, true);
            mAlertView.show();

        } else {

            if (_addLogUpLoadInfo.isToastToUser()) {
                ToastUtils.showShort(resultMessage);
            } else {
                LogUtils.d(ConstantSign.LOGCAT_NOMAL + getResources().getString(R.string.donot_to_user));
            }

        }

    }

}
